package com.rabbiter.market.controller.user.shoppingcart;

import com.rabbiter.market.common.web.response.JsonResult;
import com.rabbiter.market.domain.shoppingcart.ShoppingCart;
import com.rabbiter.market.qo.shoppingcaet.ShoppingCartQo;
import com.rabbiter.market.service.shoppingcart.ShoppingCartService;
import com.rabbiter.market.vo.goods.GoodsListVo;
import com.rabbiter.market.vo.shoppingcart.ShoppingCartVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author: longxianghang
 * @date: 2025/3/20 17:26
 * @description:
 */
@RestController
@RequestMapping("/shopping-cart")
public class ShoppingCartController {

    @Resource
    private ShoppingCartService shoppingCartService;

    @PostMapping("/add-goods-to-cart")
    public JsonResult<Boolean> addGoodsToCart(@RequestBody ShoppingCart shoppingCart, HttpServletRequest request) {
        String token = request.getHeader("token");
        return JsonResult.success(shoppingCartService.addGoodsToCart(shoppingCart, token));
    }

    // TODO 添加条件分页
    @GetMapping("/get-cart-list")
    public JsonResult<List<ShoppingCartVo>> getCartList(ShoppingCartQo qo, HttpServletRequest request) {
        String token = request.getHeader("token");
        return JsonResult.success(shoppingCartService.getCartList(qo, token));
    }

    @PostMapping("/update-cart-num")
    public JsonResult<Boolean> updateCartNum(@RequestBody ShoppingCart shoppingCart, HttpServletRequest request) {
        String token = request.getHeader("token");
        return JsonResult.success(shoppingCartService.updateCartNum(shoppingCart, token));
    }

    @DeleteMapping("/delete-cart-goods/{ids}")
    public JsonResult<Boolean> deleteCartGoods(@PathVariable List<Long> ids, HttpServletRequest request) {
        return JsonResult.success(shoppingCartService.deleteCartGoods(ids));
    }

}
